package project.mapper;

import org.apache.ibatis.annotations.*;
import project.pojo.CourseForSelect;
import project.pojo.Student;

import java.util.List;


public interface StudentMapper {

    @Select("select * from student where id = #{id}")
    @ResultMap("studentResultMap")
    Student selectById(long id);


    @Insert("insert into student(id, name, password, department_name, major_name) values (#{id},#{name},#{password},#{departmentName},#{majorName})")
    @ResultMap("studentResultMap")
    void addStudent(Student student);


    @Select("select * from student where id=#{id} and password= #{password}")
    @ResultMap("studentResultMap")
    Student judgeLogin(@Param("id") long id, @Param("password") String password);

    List<CourseForSelect> showAllCourses(@Param("id") long id);

    List<String> selectRecordTimes(@Param("id") long id);

    List<CourseForSelect> queryAllByInformation(@Param("userId") long userId, @Param("id") long id, @Param("name") String name, @Param("teacherName") String teacherName, @Param("type") String type);

    @Insert("insert into student_record(course_id, student_id) values (#{courseId},#{studentId})")
    int insertStudentRecord(@Param("courseId") long courseId, @Param("studentId") long studentId);

    List<CourseForSelect> showAllSelected(@Param("id") long id);

    @Delete("DELETE FROM student_record WHERE student_id=#{studentId} AND course_id=#{courseId}")
    int deleteCourseSelected(@Param("courseId") long courseId, @Param("studentId") long studentId);

    @Update("UPDATE student set password = #{password} WHERE id = #{id}")
    int updatePassword(@Param("id") long id,@Param("password") String password);

    @Update("UPDATE student set email = #{email} WHERE id = #{id}")
    int updateEmail(@Param("id") long id, @Param("email") String email);

    @Update("UPDATE student set phone = #{phone} WHERE id = #{id}")
    int updatePhone(@Param("id") long id, @Param("phone") String phone);

    @Select("SELECT * FROM student WHERE email = #{email} AND id <> #{id}")
    List<Student> selectByEmailNum(@Param("id") long id,@Param("email") String email);

    @Select("SELECT * FROM student WHERE phone = #{phone} AND id <> #{id}")
    List<Student> selectByPhoneNum(@Param("id") long id,@Param("phone") String phone);
}
